//
//  MainTabBarController.m
//  HMDemo
//
//  Created by mengxiangyu on 2017/6/15.
//  Copyright © 2017年 mengxiangyu. All rights reserved.
//

#import "MainTabBarController.h"

#import "TabBar_0_ViewController.h"
#import "TabBar_1_ViewController.h"
#import "TabBar_2_ViewController.h"
#import "TabBar_3_ViewController.h"
#import "TabBar_4_ViewController.h"
#import "TabBar_0_NavigationController.h"
#import "TabBar_1_NavigationController.h"
#import "TabBar_2_NavigationController.h"
#import "TabBar_3_NavigationController.h"
#import "TabBar_4_NavigationController.h"

static MainTabBarController *instanceMainCrl; // 用于在其他地方拿到 MainTabBarController

@interface MainTabBarController ()

@end

@implementation MainTabBarController

+ (MainTabBarController *)shareMainController {
    NSAssert([instanceMainCrl isKindOfClass:[MainTabBarController class]], @"instanceMainCrl is not MainTabBarController class");
    return instanceMainCrl;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        instanceMainCrl = self;
        
        // 移除tabbar上的黑线
        [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
        [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbarBg"]];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HM_WIDTH, 0.5)];
        [self.tabBar addSubview:line];
        line.backgroundColor = rgba(230, 230, 230, 1);
        
        [self addChildViewControllers];
    
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (void)addChildViewControllers {
    
    TabBar_0_ViewController *view_0 = [[TabBar_0_ViewController alloc] init];
    TabBar_0_NavigationController *nav_0 = [[TabBar_0_NavigationController alloc] initWithRootViewController:view_0];
    [self addChildViewController:nav_0];
    view_0.view.backgroundColor = [UIColor redColor];
    view_0.title = @"TabBar_0";
    
    TabBar_1_ViewController *view_1 = [[TabBar_1_ViewController alloc] init];
    TabBar_1_NavigationController *nav_1 = [[TabBar_1_NavigationController alloc] initWithRootViewController:view_1];
    [self addChildViewController:nav_1];
    view_1.view.backgroundColor = [UIColor orangeColor];
    view_1.title = @"TabBar_1";
    
    TabBar_2_ViewController *view_2 = [[TabBar_2_ViewController alloc] init];
    TabBar_2_NavigationController *nav_2 = [[TabBar_2_NavigationController alloc] initWithRootViewController:view_2];
    [self addChildViewController:nav_2];
    view_2.view.backgroundColor = [UIColor yellowColor];
    view_2.title = @"TabBar_2";
    
    TabBar_3_ViewController *view_3 = [[TabBar_3_ViewController alloc] init];
    TabBar_3_NavigationController *nav_3 = [[TabBar_3_NavigationController alloc] initWithRootViewController:view_3];
    [self addChildViewController:nav_3];
    view_3.view.backgroundColor = [UIColor greenColor];
    view_3.title = @"TabBar_3";
    
    TabBar_4_ViewController *view_4 = [[TabBar_4_ViewController alloc] init];
    TabBar_4_NavigationController *nav_4 = [[TabBar_4_NavigationController alloc] initWithRootViewController:view_4];
    [self addChildViewController:nav_4];
    view_4.view.backgroundColor = [UIColor blueColor];
    view_4.title = @"TabBar_4";
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:Color_Subject} forState:UIControlStateSelected];
    
}


@end
